home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / ns_admin.idb / usr / ns-home / sgi_config / admin / configure.z / configure
Encoding:
Text File  |  1997-06-26  |  4.3 KB  |  142 lines

  1. #!/bin/sh 
  2. #
  3. # /usr/ns-home/sgi_config/admin/configure
  4. #
  5. # This script fixes up the netscape admin server 2.X configuration files
  6. # if the system name, primary IP address, or domain name is  changed.
  7. # It is typically called as an exitop upon installation of the image and from
  8. # /etc/init.d/ns_admin each time the system boots.
  9. #
  10. # The script first checks to see if any key system configuration has changed.
  11. # If so, it does its work
  12. #
  13. #     $Revision: 1.1 $
  14. #
  15. #
  16.  
  17. SED=/usr/bin/sed
  18. GREP=/usr/bin/grep
  19. SORT=/usr/bin/sort
  20. HEAD=/usr/bsd/head
  21. CPP='/bin/cp -p'
  22. MV=/bin/mv
  23. RM=/bin/rm
  24. CAT=/usr/bin/cat
  25.  
  26. IS_ON=/sbin/chkconfig
  27.  
  28. if $IS_ON verbose; then
  29.    ECHO=echo
  30. else
  31.    ECHO=:
  32. fi
  33.  
  34. NS_HOME=/usr/ns-home
  35. CONFIG_DIR=$NS_HOME/sgi_config/admin
  36.  
  37. HOST_FLAG=%%HOSTNAME%%
  38. DOMAIN_FLAG=%%DOMAINNAME%%
  39. ADDR_FLAG=%%NETADDR%%
  40.  
  41. if [ -f ${CONFIG_DIR}/%%DOMAINNAME%% -a -f ${CONFIG_DIR}/%%HOSTNAME%% -a -f ${CONFIG_DIR}/%%NETADDR%% ]; then
  42.    :
  43. else
  44.    $ECHO "$0: config files missing from ${CONFIG_DIR}"
  45.    exit 1
  46. fi
  47.  
  48. OLDDOMAIN=`$CAT ${CONFIG_DIR}/%%DOMAINNAME%%`
  49. OLDHOST=`$CAT ${CONFIG_DIR}/%%HOSTNAME%%`
  50. OLDADDR=`$CAT ${CONFIG_DIR}/%%NETADDR%%`
  51.  
  52. NAMELIST=`$CAT ${CONFIG_DIR}/namelist`
  53. EDITLIST=`$CAT ${CONFIG_DIR}/editlist | \
  54.    $SED "s/$HOST_FLAG/$OLDHOST/" | $SED "s/$DOMAIN_FLAG/$OLDDOMAIN/" | \
  55.    $SED "s/$ADDR_FLAG/$OLDADDR/"`
  56.  
  57. ADM_NAME_LIST=${NS_HOME}/admserv/${NAMELIST}
  58.  
  59.  
  60. # first get the current hostname and domainname and address
  61. # hostname
  62. #
  63. canonname=`/usr/etc/configmail get mycanonname`
  64.  
  65. hostname=`/usr/bin/echo $canonname | $SED 's/\..*//'`
  66. if [ "$hostname" = "" ]; then
  67.    $ECHO "$0: Cannot get hostname for system."
  68.    exit 1
  69. fi
  70.  
  71. #domainname
  72. #
  73. domainname=`/usr/etc/configmail get localdomain`
  74. if [ "$domainname" = "" ]; then
  75.    domainname=$DOMAIN_FLAG
  76. fi
  77.  
  78. #netaddr
  79. netaddr=`$GREP $canonname /etc/hosts |  $GREP -v "^#" | $SED 's/[     ].*//' | $SORT -u | $HEAD -1`
  80. if [ "$netaddr" = "" ]; then 
  81.    netaddr=`$GREP $hostname /etc/hosts |  $GREP -v "^#" | $SED 's/[     ].*//' | $SORT -u | $HEAD -1`
  82. fi
  83. if [ "$netaddr" = "" ]; then
  84.    netaddr=$ADDR_FLAG
  85. fi
  86.  
  87. # See if anything has changed -- Don't do this. For the ns_admin configuration
  88. # files we'll always attempt to edit them. Since they are config(suggest), the
  89. # user could move the .N file over the existing one at any time. This way we
  90. # always catch it. Since there is such a small file set, this is not an
  91. # expensive solution.
  92. #
  93. #if [ "$domainname" = "$OLDDOMAIN" -a "$hostname" = "$OLDHOST" -a "$netaddr" = "$OLDADDR" ]; then
  94. #    $ECHO "$0: no changes"
  95. #    exit 0
  96. #fi
  97.  
  98. # Now edit the files -- THIS MUST BE DONE BEFORE CHANGING DIRECTORY NAMES
  99. # Note I always try to change the canon names (the *_FLAG) because there may be a .N
  100. # file that the user moves over the existing one. The special expressions 
  101. # "^ServerName" and "^Hosts" are need to be called out in particular
  102. # because host names can look like other strings. Note that these SED commands
  103. # must be run in this order.
  104. #
  105. for dir in $ADM_NAME_LIST
  106. do
  107.    for file in $EDITLIST
  108.    do
  109.       $CPP $NS_HOME/$file $NS_HOME/$file.tmp    #preserver owner, permission, etc
  110.       $SED  "s/^\(ServerName[     ]*\).*/\1$canonname/"  $NS_HOME/$file | \
  111.       $SED  "/^Hosts[     ]*/s/($HOST_FLAG|/($canonname|/" | \
  112.       $SED  "/^Hosts[     ]*/s/|$HOST_FLAG)/|$canonname)/" | \
  113.       $SED  "/^Hosts[     ]*/s/|$HOST_FLAG|/|$canonname|/" | \
  114.       $SED  "/^Hosts[     ]*/s/($HOST_FLAG)/($canonname)/" | \
  115.       $SED  "/^Hosts[     ]*/s/($OLDHOST|/($canonname|/" | \
  116.       $SED  "/^Hosts[     ]*/s/|$OLDHOST)/|$canonname)/" | \
  117.       $SED  "/^Hosts[     ]*/s/|$OLDHOST|/|$canonname|/" | \
  118.       $SED  "/^Hosts[     ]*/s/($OLDHOST)/($canonname)/" | \
  119.       $SED  "s/^\(Hosts[     ]*\)$HOST_FLAG/\1$canonname/" | \
  120.       $SED  "s/^\(Hosts[     ]*\)$OLDHOST[     ]*$/\1$canonname/" | \
  121.       $SED  "s/$HOST_FLAG.$DOMAIN_FLAG/$canonname/g" | \
  122.       $SED  "s/$HOST_FLAG.$OLDDOMAIN/$canonname/g" | \
  123.       $SED  "s/$OLDHOST.$OLDDOMAIN/$canonname/g" | \
  124.       $SED  "s/$DOMAIN_FLAG/$domainname/g" | \
  125.       $SED  "s/$OLDDOMAIN/$domainname/g" | \
  126.       $SED  "s/$ADDR_FLAG/$netaddr/g" | \
  127.       $SED "s/$OLDADDR/$netaddr/g" >$NS_HOME/$file.tmp
  128.       $MV $NS_HOME/$file.tmp $NS_HOME/$file
  129.    done
  130. done
  131.  
  132. # Remember the current host information
  133. #
  134. /usr/bin/echo $hostname >${CONFIG_DIR}/%%HOSTNAME%%
  135. /usr/bin/echo $domainname >${CONFIG_DIR}/%%DOMAINNAME%%
  136. /usr/bin/echo $netaddr >${CONFIG_DIR}/%%NETADDR%%
  137.  
  138. exit 0
  139.  
  140.